package cn.dceast.former.service;

import cn.dceast.former.dao.EyeModelContactMapper;
import cn.dceast.former.dao.EyeModelDataMapper;
import cn.dceast.former.dao.EyeModelFieldMapper;
import cn.dceast.former.model.EyeModelData;
import cn.dceast.former.model.EyeModelField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fanbo on 2017-07-18.
 *
 */
@Service
public class EyeModelService {

    @Autowired
    private EyeModelDataMapper eyeModelDataMapper;
    @Autowired
    private EyeModelFieldMapper eyeModelFieldMapper;
    @Autowired
    private EyeModelContactMapper eyeModelContactMapper;

    /**
     * 根据条件查询模型列表
     * @param params
     * @return
     */
    public List<Map<String,Object>> getModelList(Map<String, Object> params) {
        List<Map<String,Object>> modelList = eyeModelDataMapper.getModelList(params);
        return  modelList;
    }


    /**
     * 根据条件查询模型列表数量
     * @param params
     * @return
     */
    public Integer getModelListCount(Map<String, Object> params) {
        Integer modelCount = eyeModelDataMapper.getModelListCount(params);
        return  modelCount;
    }

    /**
     * 根据模型ID查询模型的详细信息
     * @param paramMap
     * @return
     */
    public List<Map<String,Object>> getModelInfoById(Map<String, Object> paramMap) {
        List<Map<String,Object>> modelInfoList = eyeModelDataMapper.getModelInfoById(paramMap);
        return  modelInfoList;
    }

    /**
     *模型的基本信息添加
     * @param eyeModelData
     */
    public int addModelBasicInfo(EyeModelData eyeModelData) {
       return  eyeModelDataMapper.addModelBasicInfo(eyeModelData);
    }


    public Map<String,Object> getModelDataById(int modelId) {
        return  eyeModelDataMapper.getModelDataById(modelId);
    }

    public Map<String,Object> getModelEvalUateById(int modelId, int userId) {
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("modelId",modelId);
        paramMap.put("userId",userId);
        return  eyeModelDataMapper.getModelEvalUateById(paramMap);
    }

    public List<EyeModelField> getModelFieldDataById(String modelId) {
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("modelId",modelId);
        return  eyeModelFieldMapper.getModelFieldDataById(paramMap);
    }

    public void addModelContact(Map<String, Object> map) {
        eyeModelContactMapper.addModelContactIndustry(map);
    }

    public void addModelContactScene(Map<String, Object> map) {
        eyeModelContactMapper.addModelContactScene(map);
    }

    public List<Map<String,Object>> getModelByName(Map<String, Object> paramMap) {
        return eyeModelDataMapper.getModelByName(paramMap);
    }

    public void deleteModelByName(Map<String, Object> paramMap) {
        //先删除关系表
        eyeModelContactMapper.deleteByName(paramMap);
        //再删除模型表
        eyeModelDataMapper.deleteModelByName(paramMap);

    }

    public void deleteModelById(Map<String, Object> paramMap) {
        //先删除关系表
        eyeModelContactMapper.deleteById(paramMap);
        //再删除模型表
        eyeModelDataMapper.deleteModelById(paramMap);

    }

    public void  deleteContactByModelId(Map<String, Object> paramMap){
        //先删除关系表
        eyeModelContactMapper.deleteById(paramMap);
    }

    public void editModelBasicInfo(EyeModelData emd) {
        eyeModelDataMapper.editModelBasicInfo(emd);
    }

    public void deleteContact(int modelId) {
        eyeModelContactMapper.deleteContactByModelId(modelId);
    }

    public void updateModelState(Map<String, Object> paramMap) {
        eyeModelDataMapper.updateModelState(paramMap);
    }

    public List<Map<String,Object>> getModelFieldById(int modelId) {

        List<Map<String,Object>> modelMap = eyeModelDataMapper.getModelNameAndDescById(modelId);
        return modelMap;
    }

    public List<Map<String,Object>> getModelTableById(int modelId) {
        List<Map<String,Object>> modelMap = eyeModelDataMapper.getModelTableById(modelId);
        return modelMap;
    }

    public List<Map<String,Object>> getModelByIdAndName(Map<String, Object> paramMap) {
        List<Map<String,Object>> modelMap = eyeModelDataMapper.getModelByIdAndName(paramMap);
        return modelMap;
    }

    public int checkTokenState(String token) {
        return eyeModelDataMapper.checkTokenState(token);
    }

    public List<Map<String,Object>> getResDataByApi(Map<String, Object> paramMap) {
        return eyeModelDataMapper.getResDataByApi(paramMap);
    }
}
